﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Cuckoo.TaskSchedule
{
	/// <summary>
	/// 任务处理策略工厂
	/// </summary>
	internal static class TaskStrategyFactory
	{
		/// <summary>
		/// 根据任务类型创建对应的任务处理策略对象
		/// </summary>
		/// <param name="task">待处理任务</param>
		/// <returns>相应的任务处理策略对象</returns>
		public static ITaskStrategy CreateTaskStrategy(ITask task)
		{
			switch (TaskStrategyHelper.GetType(task))
			{
				case TaskType.INTERNAL_TASK:
					return IntervalTaskStrategy.Instance;
				case TaskType.SOLID_TASK:
					return FixedTaskStrategy.Instance; 
				default:
					throw new ExpressionException(task.ScheduleExpress);
			}
		}

		/// <summary>
		/// 获取间隔时间处理策略对象
		/// </summary>
		/// <returns></returns>
		public static ITaskStrategy GetIntervalTaskStrategy()
		{
			return IntervalTaskStrategy.Instance;
		}

		/// <summary>
		/// 获取固定时间处理策略对象
		/// </summary>
		/// <returns></returns>
		public static ITaskStrategy GetSolidTaskStrategy()
		{
			return FixedTaskStrategy.Instance;
		}
	}
}
